import path from 'path';
import fs from 'fs';
import cjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';

const pkgPath = path.resolve(__dirname, '../../packages');
const distPath = path.resolve(__dirname, '../../dist/node_modules');

export function resolvePkgPath(name, isDist) {
 if(isDist){
    return `${distPath}/${name}`;
 }else{
    return `${pkgPath}/${name}`;
 }
}

export function getPackageJson(name) {
    //包路径
    const path = `${resolvePkgPath(name)}/package.json`;
    const str = fs.readFileSync(path, { encoding: 'utf-8' });
    return JSON.parse(str);
}

export function getBaseRollupPlugins({ ts = {}} = {}){
    return [
        cjs(),
        typescript(ts)
    ]
}